using System.IO;
using System.Text;

namespace iTunesExport.Parser
{
    /// <summary>
    /// Represents an individual audio track from the iTunes library.
    /// </summary>
    public class Track
    {        

        public static Track CreateDemoTrack()
        {
            return new Track("12345", "Enter 1", "Sol Seppy","375",@"Z:\Musik\2008\Various\12 Enter 1.mp3", true, false, "Alternative","The Bells of 1 2",false);
        }
                
        public Track( string id, string name, string artist, string trackTime, string location, bool inLibrary, bool disabled,
            string genre, string album, bool isVideo)
        {
            Id = id;
            Name = name ?? string.Empty;
            Artist = artist ?? string.Empty;
            Genre = genre ?? string.Empty;
            int time;
            int.TryParse(trackTime, out time);
            TrackTime = time/1000; //in secs
            Location = location;
            InLibrary = inLibrary;
            Disabled = disabled;
            
            Album = album;
            IsVideo = isVideo;
        }
        public string Id { get; private set; }
        public string Name { get; private set; }
        public bool IsVideo { get; private set; }
        public bool InLibrary { get; private set; }
        public bool Disabled { get; private set; }
        public int TrackTime { get; private set; }
        public string Artist { get; private set; }
        public string Location { get; private set; }
        public string LocationUtf8 { get; set; }
        public string Genre { get; private set; }
        public string Album { get; private set; }

        public string FileName
        {
            get
            {
                return Path.GetFileName(Location);                
            }
        }
        public string FileNameUtf8
        {
            get
            {
                return Path.GetFileName(LocationUtf8);
            }
        }
             
        public override string ToString()
        {             
            return 
                new StringBuilder().Append(Genre).Append("-").Append(Artist).Append("-").Append(Album).
                Append("-").Append(Name).ToString();          
        }
    }
}
